#include "mprotocol.h"
#include "global.h"

#define BYTE unsigned char
CMyProtocol::CMyProtocol(void)
{
}

CMyProtocol::~CMyProtocol(void)
{
}

void CMyProtocol::Login_read(IN char *streambuf, OUT char *name, OUT char *pwd)
{
	CByteStream bs((BYTE*)streambuf);
	int len = 0;
	bs>>len;
	bs.Read(name, len);
	bs>>len;
	bs.Read(pwd, len);
}

void CMyProtocol::Login_write(OUT char *streambuf, OUT int &len, IN char *name, IN char *pwd)
{
	CMPLoginHeader lh = {0};
	lh._type = NPT_LOGIN;
	
	CMPLoginBody lb = {0};
	lb.namelen = strlen(name);
	lb.pwdlen = strlen(pwd);
	lh._length = sizeof(short)*2 + lb.namelen + lb.pwdlen;
	len = sizeof(lh._type) + sizeof(lh._length) + lh._length;

	streambuf = new char[len];
	memset(streambuf, 0, len);
	CByteStream bs((BYTE*)streambuf);
	bs<<lh._type;
	bs<<lh._length;
	bs<<lb.namelen;
	bs.Write(name, lb.namelen);
	bs<<lb.pwdlen;
	bs.Write(pwd, lb.pwdlen);
}
